//
//  UIViewControls.m
//  WisdomPartyBuilding
//
//  Created by Can on 2018/4/23.
//  Copyright © 2018年 hwd. All rights reserved.
//

#import "UIViewControls.h"

@implementation UIViewControls

+ (UIButton *)creatBtn:(CGRect)rect imageName:(NSString *)imageName text:(NSString *)text
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = rect;
    button.backgroundColor = [UIColor whiteColor];
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake((rect.size.width - 40*screenW_6)/2, 10*screenW_6, 40*screenW_6, 40*screenW_6)];
    imageView.image = [UIImage imageNamed:imageName];
    [button addSubview:imageView];
    
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView.frame) + 4*screenW_6, rect.size.width, 12*screenW_6)];
    lable.text = text;
    lable.textAlignment = NSTextAlignmentCenter;
    lable.font = [UIFont systemFontOfSize:12*screenW_6];
//    lable.textColor = Color(102, 102, 102);
    [button addSubview:lable];
    
    return button;
}

+ (UIButton *)creatButton:(CGRect)rect title:(NSString *)title
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = rect;
    [button setTitle:title forState:UIControlStateNormal];
    [button setTintColor:[UIColor colorWithHexString:@"#e5eafd"]];
    button.titleLabel.font = [UIFont systemFontOfSize:36.02/2*screenW_6];
    return button;
}

+ (UIButton *)creatButtonBackImage:(CGRect)rect imageName:(NSString *)imageName
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = rect;
    [button setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    return button;
}

+ (UIButton *)creatButtonSetImage:(CGRect)rect imageName:(NSString *)imageName
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = rect;
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    return button;
}

+ (UIImageView *)creatImageView:(CGRect)rect imageName:(NSString *)imageName
{
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:rect];
    imageView.image = [UIImage imageNamed:imageName];
    return imageView;
}

+ (UILabel *)creatLable:(CGRect)rect text:(NSString *)text textColor:(UIColor *)textColor textFont:(UIFont *)font
{
    UILabel *lable = [[UILabel alloc]initWithFrame:rect];
    lable.text = text;
    lable.textColor = textColor;
    lable.font = font;
    lable.textAlignment = NSTextAlignmentCenter;
    return lable;
}


+ (CGFloat)lableHeight:(UILabel *)lable{
    lable.numberOfLines = 0;
    lable.lineBreakMode = NSLineBreakByTruncatingTail;
    CGSize maximumLabelSize = CGSizeMake(lable.frame.size.width, 9999);//labelsize的最大值
    CGSize expectSize = [lable sizeThatFits:maximumLabelSize];
    return expectSize.height;
}

+ (void)creatAlertWithTarget:(UIViewController *)vc message:(NSString *)message timeInterval:(CGFloat)timeInterval
{
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(SCREENW/6, SCREENH/3*2, SCREENW/3*2, 100)];
    label.text = message;
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont systemFontOfSize:15];
    label.textAlignment = NSTextAlignmentCenter;
    [vc.view addSubview:label];

    label.backgroundColor = [UIColor blackColor];

    [UIView animateWithDuration:timeInterval animations:^{
        label.alpha = 0;
    } completion:^(BOOL finished) {
        [label removeFromSuperview];
    }];
}

@end
